package com.investmenttechnologyservices.model;

import java.util.Currency;

import com.google.appengine.api.datastore.Entity;
import com.google.appengine.api.datastore.Key;

public class Symbol extends EntityHolder {
	//@Id String id;  // symbol is the id
	//@Parent Key instrumentKey;
	//Key  dataProviderKey; //Always 
	//Key exchangeKey;
	//Currency currency;
	//PriceFormat priceFormat;
	
	
	public Symbol(Entity entity) {
		super(entity);
	}
	
	public Symbol(String id, Key instrumentKey) {
	    super("symbol", id, instrumentKey);
	}
	
	public Symbol(String id, Key instrumentKey,  Key dataProviderKey, 
			Key exchangeKey, Currency currency) {
		this(id, instrumentKey);
		setDataProviderKey(dataProviderKey);
		setExchangeKey(exchangeKey);
		setCurrency(currency);
	}
	
	public Key getKey() {
		return super.getKey();
	}
	
	public Key getDataProviderKey() {
		return (Key) getProperty("dataProviderKey");
	}

	public void setDataProviderKey(Key dataProviderKey) {
		setProperty("dataProviderKey",dataProviderKey);
	}

	public Key getExchangeKey() {
		return (Key) getProperty("exchangeKey");
	}

	public void setExchangeKey(Key exchangeKey) {
		setProperty("exchangeKey",exchangeKey);
	}

	public Currency getCurrency() {
		String strCurrency = (String)getProperty("currency");
		return Currency.getInstance(strCurrency);
	}

	public void setCurrency(Currency currency) {
		setProperty("currency",currency.getCurrencyCode());
	}
	
	public PriceFormat getPriceFormat() {
		String storedValue = (String) getProperty("priceFormat");
		if (storedValue == null) {
			return null; // null at Symbol level should redirect to Instrument level.
		} else {
			return PriceFormat.valueOf(storedValue);
		}
	}
	
	public void setPriceFormat(PriceFormat priceFormat){
		if (priceFormat == null || priceFormat == PriceFormat.SIMPLE) {
			setProperty("priceFormat",null, true);
		} else {
			setProperty("priceFormat",priceFormat.name());
		}
	}


	@Override
	public String toString() {
		return "Symbol [id=" + getId() + ", InstrumentKey=" + getParentId() + ", dataProviderKey="
				+ getDataProviderKey() + ", exchangeKey=" + getExchangeKey() + ", currency="
				+ getCurrency() + ", priceFormat="+getPriceFormat()+"]";
	}

}
